package com.cx.controller;

import com.cx.service.GroupGoodsService;
import com.cx.util.RequestResult;
import com.cx.vo.GroupGoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author: Zhou wei
 * @create: 2020/5/27 22:45
 */
@Controller
@RequestMapping("groupbuy")
public class GroupGoodsController {

    @Autowired
    GroupGoodsService groupGoodsService;

    /**
     * 跳转团购页面，及团购商品显示
     * @return
     */
    @RequestMapping("groupgoods")
    public ModelAndView showGroupGoods(){
        ModelAndView modelAndView = new ModelAndView();

        List<GroupGoodsVO> groupGoodsVOList = groupGoodsService.selectAll();

        modelAndView.addObject("groupGoodsVOList",groupGoodsVOList);
        modelAndView.setViewName("groupbuy");
        return modelAndView;
    }

    @RequestMapping("searchByGroupGoodName")
    @ResponseBody
    public RequestResult searchByGroupGoodName(String groupGoodName){
        List<GroupGoodsVO> groupGoodsVOList = groupGoodsService.searchByGroupGoodName(groupGoodName);
        return new RequestResult(1,"查询成功",groupGoodsVOList);
    }

}
